#ifndef EPIK_CONTROLLER_H_
#define EPIK_CONTROLLER_H_
/**
 * @author justin.drobey@gmail.com
 *
 * Class Epik_Controller
 * A class that allows you to check the status of all your buttons in a standalone thread
 * so your main game loop just has to check the button it wants when you need to.
 */
#include <pspctrl.h>
#include <pspkerneltypes.h>

class Epik_Controller {
public:
	enum BUTTONS {
		DPAD_UP = 0,
		DPAD_DOWN = 1,
		DPAD_LEFT = 2,
		DPAD_RIGHT = 3,
		BTN_TRIANGLE = 4,
		BTN_CROSS = 5,
		BTN_SQUARE = 6,
		BTN_CIRCLE = 7,
		TRIGGER_LEFT = 8,
		TRIGGER_RIGHT = 9,
		HUB_START = 10,
		HUB_SELECT = 11,
		STICK_AXISX = 12,
		STICK_AXISY = 13
	};

private:
	unsigned int delay_;
	SceUID thid_;		// the thread's ID
	bool *running_;		// pointer to the main RUN variable (handled by HOME button)
	static const int NUM_BUTTONS__ = 12;	// 14, but the joystick isn't a bool so its 2 axis don't count.
	bool **pButtons_;	// Holds the info
	bool useless_;		// buttons' default pointer
	u8 useless2_;
	bool threadRun_;	// BOOL that tells the thread if it should run
	u32 buttons_;
	u8 *Lx_, *Ly_;	// Pointers to the stick's X and Y

public:
	Epik_Controller(bool *run, unsigned int readDelay = 10000);
	~Epik_Controller();

	u32 UpdateButtons();
	void BindButton(enum BUTTONS pos, void *ptr);
	unsigned int Buttons() const;
	void Start();
	void Stop();

	bool *getpointer()
	{ return &threadRun_; }

	bool isRunning() const;
	unsigned int GetDelay() const;
};

#endif
